import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from sklearn.decomposition import PCA
from matplotlib import cm

# 生成随机数据
data = np.random.rand(1000, 6)

# PCA降维到3维
pca = PCA(n_components=3)
new_data = pca.fit_transform(data)

# 归一化向量长度
lengths = np.linalg.norm(data, axis=1)
normalized_lengths = (lengths - np.min(lengths)) / (np.max(lengths) - np.min(lengths))

# 归一化向量
normalized_data = data / np.max(lengths)

# 绘制向量场
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.quiver(new_data[:, 0], new_data[:, 1], new_data[:, 2], normalized_data[:, 0], normalized_data[:, 1], normalized_data[:, 2], color=cm.jet(normalized_lengths))
plt.show()